/*
 Copyright (C) 2009 QDSS.org
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.qdss.persist.engine;

import org.qdss.persist.Field;
import org.qdss.persist.engine.entry.ID;

/**
 * 
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">FANGFANG ZHAO</a>
 * @since 0.1.0, Feb 20, 2009
 * @version $Id: SystemEntities.java 51 2009-05-06 07:45:48Z zhaofang123@gmail.com $
 */
public final class SystemEntities {
	
	public static String formatReferencesMappingSelect(Field field, ID[] recordIds) {
		StringBuilder ql = new StringBuilder("select recordId, referenceId from ReferencesMapping where")
			.append( " entity = " )
			.append( field.getOwnEntity().getEntityCode() )
			.append( " and field ='" )
			.append( field.getName() )
			.append("' and recordId in ( ");
		
		boolean first = true;
		for (ID rId : recordIds) {
			if (first)
				first = false;
			else
				ql.append(", ");
			ql.append('\'').append(rId.toLiteral()).append('\'');
		}
		
		return ql.append(" )").toString();
	}
	

	// --------------------------------------------------------------------------------
	
	static class ReferencesMapping {
		public static final String NAME 		= "ReferencesMapping";
		public static final String uniqueId 	= "uniqueId";
		public static final String entity 		= "entity";
		public static final String field 		= "field";
		public static final String recordId 	= "recordId";
		public static final String referenceId 	= "referenceId";
	}
	
	static class LobHash {
		public static final String NAME 		= "LobHash";
		public static final String uniqueId 	= "uniqueId";
		public static final String entity 		= "entity";
		public static final String field 		= "field";
		public static final String recordId 	= "recordId";
		public static final String hash		 	= "hash";
	}
}
